package com.aps.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.aps.entity.ResultEntity;
import com.aps.entity.domain.dish.Dish;
import com.aps.page.BaseQuery;
import com.aps.service.IDishService;
import com.aps.service.rep.DishRep;
import com.aps.service.rep.DishSpecRep;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author liaoguangan
 * @description <>
 * @date 2018/4/9 15:55
 */
@RestController
@RequestMapping("/manage-api")
@Api(value = "manage-dish-api", description = "菜品管理接口")
public class DishApi {

    //////////////////菜品管理相关////////////////////////////////

    @Autowired
    private IDishService dishService;

    @Autowired
    private DishSpecRep dishSpecRep;

    @Autowired
    private DishRep dishRep;

    @RequestMapping(value = "/all-dish", method = RequestMethod.GET)
    @ApiOperation("查询全部菜品")
    public ResultEntity allDish() {
        return new ResultEntity(dishRep.findAll());
    }

    @RequestMapping(value = "/list-dish", method = RequestMethod.POST)
    @ApiOperation("查询菜品列表信息")
    public ResultEntity listDish(@RequestBody BaseQuery baseQuery) {
        return new ResultEntity(dishService.listDishes(baseQuery));
    }

    @RequestMapping(value = "/dish/{id}", method = RequestMethod.GET)
    @ApiOperation("查询菜品详细信息")
    public ResultEntity dishDetail(@PathVariable("id") String id) {
        return new ResultEntity(dishService.findById(id));
    }

    @RequestMapping(value = "/dish-spec", method = RequestMethod.GET)
    @ApiOperation("查询菜品规格信息")
    public ResultEntity listDishSpec() {
        return new ResultEntity(dishSpecRep.findAll());
    }

    @RequestMapping(value = "/dish", method = RequestMethod.PUT)
    @ApiOperation("更新菜品信息")
    public ResultEntity updateDish(@RequestBody Dish dish) {
        dishService.update(dish);
        return new ResultEntity(true);
    }

}
